package amushen.utils;

public class StringUtil {

	 /**
	 * for some reason, flex's json can't decode " <> 
	 * so we need to encode these symbols
	 * @param s
	 * @return
	 */
	public static String encodeForASJSON(String s){
		if(s==null)return null;
		if(s.length()<1)return "";
		StringBuffer sb=new StringBuffer();
		for(int i=0;i<s.length();i++){
			switch(s.charAt(i)){
			case '<':
				sb.append("\\u003c");
				break;
			case '>':
				sb.append("\\u003e");
				break;
			case '"':
				sb.append("\\u0022");
				break;
			default:
				sb.append(s.charAt(i));
			}
		}
		return sb.toString();
	}
	
	
//	public static void main(String[] arg){
//		System.out.println(StringUtil.encodeForASJSON("{a:a<>\"bb}"));
//	}
}
